﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DTO;

namespace DAO
{
    public class BanDAO
    {
        public static DataTable Danhsachban(int Makv)
        {
            string sql = string.Format("select * from BAN Where MAKV={0}", Makv);
            return DataProvider.ExcuteQuery(sql);
        }
        public static int Themban(BanDTO ban)
        {
            string sql =string.Format("insert into BAN(MAKV,SUCCHUA,TINHTRANG) values ('{0}','{1}','{2}')",ban.Makv,ban.Succhua,ban.Trangthai);
            return DataProvider.ExcuteNonQuery(sql);
        }
        public static int SetTrangThai(int maban, int status)
        {
            string sql = string.Format("update BAN set TINHTRANG='{0}' where MABAN={1}",status,maban);
            return DataProvider.ExcuteNonQuery(sql);
        }
        public static int Update(int maban, int sl, int makv,int trangthai)
        {
            string sql =string.Format("update BAN set ");
            if (sl > 0)
                sql += string.Format("SUCCHUA={0}", sl);
            if (makv > 0)
                sql += string.Format("MAKV={0}", makv);
            if (trangthai != -1)
                sql += string.Format("TINHTRANG={0}", trangthai);
            sql += string.Format("Where MABAN={0}", maban);
            return DataProvider.ExcuteNonQuery(sql);

        }
        public static int Xoaban(BanDTO ban)
        {
            string sql = string.Format("delete BAN where MABAN={0} AND TINHTRANG={1}", ban.Maban, ban.Trangthai);
            return DataProvider.ExcuteNonQuery(sql);

        }
    }
}
